package com.ubao.activity;

import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.Vector;

import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.os.Bundle;

import com.ubao.global.crashhandler.CrashHandler;
import com.ubao.location.LocationHandler;
import com.ubao.ui.SlidingMenuView;
import com.ubao.util.log.Logger;
import com.ubao.weibo.WeiboConstant;


/**
 * 
 * @author xingyi
 * 
 */
public class MyApp extends Application {
	public static final int MAX_PAGE = 30;
	public static String mSSOCookie1;
	public static String mSSOCookie2;
	public static String iPass;
	public static SlidingMenuView slidingMenuView;
	public static Map<String,String> map = new HashMap<String,String>();

	public static boolean mHasNewArticle = false;

	public SoftReference<GoBack> mReference = new SoftReference<GoBack>(
			new GoBack());// 防止Goback被卸载

	public static boolean mBestTone = false;

//	public static com.eastmoney.android.finance.bean.user.User mUser = new com.eastmoney.android.finance.bean.user.User();
	
	public static WeiboConstant weiboUser;
	
	public static boolean isLogin;

	/**
	 * 通行证是否自动登录
	 */
	public static boolean fPassAuLogin = false;

	/**
	 * 是否为漫游标志状态位
	 */
	public static boolean mPassFlag = false;

	public static boolean mPassLoginSuccess = false;

	public static String mCid = "";

	public static boolean[] SyncFlagDismiss = { false, false, false };

	public static final boolean DEBUG = false;

	public static String Test_HTTP_URL = "";

	public static boolean needRelogin = false; // 是否需要重新登录

	public static String userNameStr;

	public static String passWordStr;

	// public static User user;

	public static boolean auto_login = true; // 是否为自动登录

	public static boolean isTest = false; // 是否为自己的测试包

	public static boolean isPopUpOn = false; // 弹窗功能是否开启

	public static boolean isFeedBackOn = true; // 后台反馈功能是否开启

	/**
	 * 标记是否为免费版
	 */
	public static final boolean FREE_VERSION = true;// 标记 免费版或是收费版

	public static boolean needLoop = false;// 是否需要去循环请求

	public static boolean hasInitNetWork = false;// 程序刚进去判断是否有网络

	public static List<Activity> activityList = new ArrayList<Activity>(); // activity管理

	public static String HTTP_URL_LICAI = "112.224.82.237"; // licai服务器

	public static String HTTP_NEW_INFO = "222.73.55.210:80";// 资讯新服务器

	public static String HTTP_REALTIME_URL_HOST = "123.129.204.227:2860"; // 行情服务器
//
	public static String HTTP_HISTORY_URL_HOST = "124.95.138.205:1861"; // 历史服务器

	public static boolean NeedResume = false;


	// 信息地雷
	public static String HTTP_LandMine_URL_HOST = "114.80.234.10"; // 信息地雷服务器


	/** 其他服务器ip列表免费 */
	public static String[] OTHER_SVR_DX_URLS = new String[] { "112.224.82.237" };

	public static String[] OTHER_SVR_WT_URLS = new String[] { "112.224.82.237" };


	/** 资讯服务器ip列表收费 */
	public static String[] NEWS_SVR_DX_URLS = new String[] { "222.73.55.210:80" };

	public static String[] NEWS_SVR_WT_URLS = new String[] { "123.129.204.239:80" };


	public static String popUpUpdateTime; // 弹窗最新更新时间

	public static boolean isWifi = false; // 当前是否为Wifi连接

	public static boolean isNeedWrite = true; // 当前需要重新写入自选股

	private int stateForLandmine = 0; // 1-from信息地雷，F10 2-from自选，资讯

	public int getStateForLandmine() {
		return stateForLandmine;
	}

	public void setStateForLandmine(int stateForLandmine) {
		this.stateForLandmine = stateForLandmine;
	}

	private boolean isExistUpdate = false; // 当前是否存在更新标识
	/**
	 * 判断是否在股票搜索界面做了操作，是的话返回简易自选界面，否则返回上一界面
	 */
	public static boolean hasChangedStock = false;

	public boolean isExistUpdate() {
		return isExistUpdate;
	}

	public void setExistUpdate(boolean isExistUpdate) {
		this.isExistUpdate = isExistUpdate;
	}

	public boolean VecFreeStockIsFull() {
		return vecFreeStock.size() >= 200;
	}

	/**
	 * 判断是否为大盘指数
	 * 
	 * @param code
	 * 
	 * 
	 * 
	 *            代码
	 * @return
	 */
	public static boolean isDaPan(String code) {

		if (code.startsWith("SH000") || code.startsWith("SZ399"))
			return true;

		return false;
	}

	public String getStockName(int pageIndex, int index) {
		int i = pageIndex * 20 + index;

		return SelfStockList.get(i)[1];
	}

	private boolean fromWidget = false;

	public boolean getFromWidget() {
		return fromWidget;
	}

	public void setFromWidget(boolean value) {
		fromWidget = value;
	}

	private static MyApp self;
	
	public static LocationHandler locationManager;

	public void onCreate() {
		self = this;
		super.onCreate();
		// 不要造成软件不可预知问题！
		CrashHandler crashHandler = CrashHandler.getInstance();
		crashHandler.init(getApplicationContext());
		crashHandler.sendPreviousReportsToServer();
		InitGubaApp();
		weiboUser = new WeiboConstant();
		locationManager = new LocationHandler(this);
	}

	/** 初始话GubaApp */
	public void InitGubaApp() {
//		MyApp.dmsc = new DataManagerServiceConnection(this);
//		LoadUserInfo();
//		///StockManager.getInstance().setContext();
//		UpdateManager.getInstance().startUpdate();
		GoBack.initialize();
	}

	/** 结束GubaApp */
	public void ExitGubaApp() {
//		if (MyApp.dmsc != null) {
//			MyApp.dmsc.Close();
//		}
//
		for (int i = MyApp.activityList.size() - 1; i >= 0; i--) {
			if (MyApp.activityList.get(i) != null) {
				MyApp.activityList.get(i).finish();
			}
		}

		MyApp.isFirstRun = true;
	}

	private void LoadUserInfo() {
//		SharedPreferences settings = getSharedPreferences("eastmoney", 0);
//		final String UserName = new BlowfishUtil(GameConst.SYNC_LOGIN_KEY)
//				.decryptString(settings.getString("PassUsrName", "")) == null ? ""
//				: new BlowfishUtil(GameConst.SYNC_LOGIN_KEY)
//						.decryptString(settings.getString("PassUsrName", ""));
//		MyApp.mUser.setUserName(UserName);
//		final String UserPswd = new BlowfishUtil(GameConst.SYNC_LOGIN_KEY)
//				.decryptString(settings.getString("PassUsrPswd", "")) == null ? ""
//				: new BlowfishUtil(GameConst.SYNC_LOGIN_KEY)
//						.decryptString(settings.getString("PassUsrPswd", ""));
//		MyApp.mUser.setUserPswd(UserPswd);
//		MyApp.mPassFlag = settings.getBoolean("PassFlag", false);
//		MyApp.fPassAuLogin = settings.getBoolean("PassAuLoginFlag", false);
	}

	public void onTerminate() {
		self = null;
		// super.onTerminate();
	}

	public static MyApp getMyApp() {
		return self;
	}

	private int date = 0;

	private int time = 0;

	public void setDate(int value) {
		this.date = value;
	}

	public void setTime(int value) {
		this.time = value;
	}

	public int getDate() {
		return this.date;
	}

	public int getTime() {
		return this.time;
	}

//	public static DataManagerServiceConnection dmsc = null;

	public static boolean isFirstRun = true;

	// 全球指数开收盘时间
	private Vector<HashMap<String, String>> vecGlobalStockTime = new Vector<HashMap<String, String>>();

	public void addToGlobalStock(HashMap<String, String> hm) {
		vecGlobalStockTime.add(hm);
	}

	public boolean hasGlobalStock(String code) {
		String compareCode = "";
		for (int i = 0, len = vecGlobalStockTime.size(); i < len; i++) {
			compareCode = vecGlobalStockTime.get(i).get("Code");
			if (compareCode.equals("code"))
				return true;
		}
		return false;
	}

	/**
	 * 存放最近浏览的容器
	 */
	private Vector<String[]> vecLaterStock = new Vector<String[]>();

	/*
	 * 0:code, 1:name
	 */
	public Vector<String[]> getVecLaterStock() {
		return vecLaterStock;
	}

	public void addToVecLaterStock(String code, String name) {
		for (int i = 0, len = vecLaterStock.size(); i < len; i++) {
			if (code.equals(vecLaterStock.elementAt(i)[0])) {
				vecLaterStock.removeElementAt(i);
				break;
			}
		}

		if (vecLaterStock.size() >= 20) {
			vecLaterStock.removeElementAt(vecLaterStock.size() - 1);
		}
		vecLaterStock.add(0, new String[] { code, name });
	}

	/**
	 * 存放所有自选股的容器
	 */
	private Vector<String> vecFreeStock = new Vector<String>();

	public void setVecFreeStock(Vector<String> vecFreeStock) {
		this.vecFreeStock = vecFreeStock;
	}

	public void initVecFreeStock() {
		vecFreeStock.add("SH000001");
		vecFreeStock.add("SZ399001");
	}

	public int getVecFreeStockSize() {
		return vecFreeStock.size();
	}

	public int getSelfStockSize() {
		return SelfStockList.size();
	}

	public Vector<String> getVecFreeStock() {
		return vecFreeStock;
	}

	public String getVecFreeStockCode(int iIndex) {
		return vecFreeStock.get(iIndex);
	}

	public int getStockIndex(String code) {
		return vecFreeStock.indexOf(code);
	}

	public String getStockCode(int index) {
		return vecFreeStock.elementAt(index);
	}

	public void removeFromVecFreeStock(String code) {
		vecFreeStock.remove(code);
	}

	public void removeItemFromVecFreeStock(int index) {
		vecFreeStock.removeElementAt(index);
	}

	public void addToVecFreeStock(String code) {
		// vecFreeStock.add(code);
		addToFirstVecFreeStock(code);
	}

	public void addToFirstVecFreeStock(String code) {
		vecFreeStock.add(0, code);
	}

	public void changeVecFreeStockSeq(int from, int to) {
		String tempStock = vecFreeStock.elementAt(from);
		vecFreeStock.set(from, vecFreeStock.elementAt(to));
		vecFreeStock.set(to, tempStock);
	}

	/**
	 * 检查自选股容器是否已满
	 * 
	 * @return true 已满 false 未满
	 * 
	 *         public boolean VecFreeStockIsFull() { return vecFreeStock.size()
	 *         == maxFreeStockList; } 暂时不使用
	 */

	/**
	 * 检查自选股容器是否为空
	 * 
	 * @return true 为空 false 不为空
	 */
	public boolean VecFreeStockIsEmpty() {
		return vecFreeStock.size() == 0;
	}

	/**
	 * 返回自选股容器包含股票
	 * 
	 * @param code
	 *            股票代码
	 * @return true 已有<br>
	 *         false 没有
	 */
	public boolean vecFreeStockHasStock(String code) {
		return vecFreeStock.contains(code);
	}

	/**
	 * 用于分页显示的自选股：每页20个，5个容器
	 */
	private Vector<String>[] vecFreeStockList = new Vector[5];

	public void initVecFreeStockList() {
		for (int i = 0; i < vecFreeStockList.length; i++) {
			vecFreeStockList[i] = new Vector<String>();
		}
	}

	public Vector<String>[] getVecFreeStockList() {
		return vecFreeStockList;
	}

	/**
	 * 返回指定页数的所有股票列表
	 * 
	 * @param reqPageIndex
	 *            股票页数
	 * @return
	 */
	public Vector<String> getVecFreeStockList(int reqPageIndex) {
		return vecFreeStockList[reqPageIndex / 20];
	}

	/**
	 * Widget特殊逻辑
	 * 
	 * @param pageIndex
	 * @return
	 */
	public Vector<String> getElementAtvecFreeStockList(int pageIndex) {

		Vector<String> rFreeStock = new Vector<String>();

		if (vecFreeStock.size() >= 20) {
			for (int i = 0; i < 20; i++) {
				rFreeStock.add(i, vecFreeStock.get(i));
			}
		} else {
			for (int i = 0, len = vecFreeStock.size(); i < len; i++) {
				rFreeStock.add(i, vecFreeStock.get(i));
			}
		}

		return rFreeStock;
	}

	/**
	 * 取出指定位置的自选股
	 * 
	 * @param index
	 *            下标
	 * @return
	 */
	public String getElementAtVecFreeStock(int index) {

		if (index >= vecFreeStock.size()) {
			return null;
		}

		return vecFreeStock.get(index);

	}

	/**
	 * 重新设置分页显示的自选股列表
	 */
	public void changeVecFreeStockList() {
		int pageCount = getFreePageCount();
		setVecFreeStockList(pageCount);
	}

	/**
	 * 获得自选股列表的页数
	 * 
	 * @return iFreePageSum 页数
	 */
	public int getFreePageCount() {
		int reqeustNumber = 20;
		int iFreeStockSum = vecFreeStock.size();
		int iFreePageSum = 0;
		if (iFreeStockSum == 0) {
			iFreePageSum = 1;
		} else {
			if (iFreeStockSum % reqeustNumber == 0) {
				iFreePageSum = iFreeStockSum / reqeustNumber;
			} else {
				iFreePageSum = iFreeStockSum / reqeustNumber + 1;
			}
		}
		return iFreePageSum;
	}

	public void setVecFreeStockList(int pageCount) {
		int reqeustNumber = 20;
		for (int i = 0; i < 5; i++) {
			vecFreeStockList[i].clear();
		}

		if (pageCount == 1) {
			for (int k = 0; k < vecFreeStock.size(); k++) {
				vecFreeStockList[0].addElement(vecFreeStock.elementAt(k));
			}
		} else {
			for (int i = 0; i < pageCount; i++) {
				if (i == pageCount - 1) {
					for (int j = i * reqeustNumber; j < vecFreeStock.size(); j++) {
						vecFreeStockList[i].addElement(vecFreeStock
								.elementAt(j));
					}
				} else {

					for (int j = i * reqeustNumber; j < i * reqeustNumber
							+ reqeustNumber; j++) {
						vecFreeStockList[i].addElement(vecFreeStock
								.elementAt(j));
					}
				}
			}
		}
	}

	/**
	 * 股吧需要股票名和股票代码一起匹配搜索<br>
	 * <br>
	 * 该容器存放String数组来存放股票代码和名称
	 */
	private Vector<String[]> SelfStockList = new Vector<String[]>();

	public void setSelfStockList(Vector<String[]> selfStockList) {
		SelfStockList = selfStockList;
	}

	public int getSelfStockListSize() {
		return SelfStockList.size();
	}

	public void initSelfStockList() {
		SelfStockList.add(new String[] { "SH000001", "上证指数" });
		SelfStockList.add(new String[] { "SZ399001", "深证成指" });
	}

	public void removeSelfStockList(int index) {
		SelfStockList.removeElementAt(index);
	}

	public void addToSelfStockList(String[] stockInfo) {
		// SelfStockList.add(stockInfo);
		addToFirstSelfStockList(stockInfo);
	}

	public void addToFirstSelfStockList(String[] stockInfo) {
		SelfStockList.add(0, stockInfo);
	}

	public String[] getSelfStockList(int index) {
		return SelfStockList.elementAt(index);
	}

	public void changeSelfStockListSeq(int from, int to) {
		String[] tempStock = SelfStockList.elementAt(from);
		SelfStockList.set(from, SelfStockList.elementAt(to));
		SelfStockList.set(to, tempStock);
	}

	public String getStockName(int index) {
		return SelfStockList.elementAt(index)[1];
	}

	public String getStockCode2(int index) {
		return SelfStockList.elementAt(index)[0];
	}

	public Vector<String[]> getSelfStockList() {
		return SelfStockList;
	}

	private int maxFreeStockList = 100;

	public int getmMaxFreeStockList() {
		return maxFreeStockList;
	}

	private int statusBarHeight;

	public int getStatusBarHeight() {
		return statusBarHeight;
	}

	public void setStatusBarHeight(int value) {
		statusBarHeight = value;
	}

	public void exitClient() {
//		ScreenReceiver.bScreenOf_NetOn = false;// 加的特殊逻辑
//		if (com.eastmoney.android.finance.bean.user.User.mPermissionStatus == Permission.FREE_AUTHORITY) {
//			Intent intent2 = new Intent(this, LoginVerifyService.class);
//			stopService(intent2);
//		}
//		NearStockManager.clean();
//		if (MyApp.dmsc != null) {
//			MyApp.dmsc.Close();
//		}
//		
		for(int i=0;i<MyApp.activityList.size();i++){
			if (MyApp.activityList.get(i) != null) {
				MyApp.activityList.get(i).finish();
			}
		}
		locationManager.exit();

	}

	private String[][] repeatGubaStrings = {
			{ "上证指数", "szzs" }, // 指数与个股代码重复，且有股吧
			{ "A股指数", "agzs" }, { "上证50指数", "sz50" }, { "上证180", "sz180" },
			{ "基金指数", "jjzs" }, { "工业指数", "gyzs" }, { "商业指数", "syzs" },
			{ "地产指数", "dczs" }, { "综合指数", "zhzs" }, { "新综指", "xzy" },
			{ "上证380", "sz380" }, { "国债指数", "gzzs" }, { "180金融", "180jr" },
			{ "治理指数", "zlzs" }, { "180运输", "180yc" }, { "中型综指", "zxzs" },
			{ "180治理", "180zl" }, { "沪公司债", "hgsz" }, { "沪分离债", "hflz" },
			{ "180基建", "180jj" }, { "180资源", "180zy" }, { "180成长", "180cc" },
			{ "180价值", "180jz" }, { "180R成长", "180rcc" },
			{ "180R价值", "180rjz" }, { "上证能源", "szny" }, { "上证材料", "szcl" },
			{ "上证可选", "szks" }, { "上证消费", "szxf" }, { "上证医药", "szyy" },
			{ "上证电信", "szdx" }, { "上证央企", "szyq" }, { "超大盘", "cdp" },
			{ "上证小盘", "szxp" }, { "上证中小", "szzx" }, { "责任指数", "zrzs" },
			{ "上证民企", "szmq" }, { "上证地企", "szdq" }, { "上证国企", "szgq" },
			{ "全指价值", "qzjz" }, { "全R成长", "qrcc" }, { "全R价值", "qrjz" },
			{ "沪企债30", "hqz30" }, { "上证沪企", "czhq" }, { "上证周期", "szzq" },
			{ "上证龙头", "szlt" }, { "上证商品", "szsp" }, { "上证流通", "szlt" } };

	public String[][] getRepeatGubaStrings() {
		return repeatGubaStrings;
	}

	public String[][] getUnusedGuba() {
		return unusedGuba;
	}

	private String[][] unusedGuba = {
			{ "公用指数", "gyzs" },
			{ "上证工业", "szgy" }, // 指数与个股代码重复，但没有股吧
			{ "上证信息", "szxx" }, { "大盘等权", "dpdq" }, { "上证资源", "szzy" },
			{ "消费80", "xf80" }, { "能源等权", "nydq" }, { "电信等权", "dxdq" },
			{ "中证100", "zz300ny100" }, { "中证500", "zz500" },
			{ "中证800", "zz800" }, { "300能源", "" }, { "300材料", "300cl" },
			{ "300工业", "300gy" }, { "300可选", "300kx" }, { "300消费", "300xf" },
			{ "300医药", "300yy" }, { "300信息", "300xx" }, { "300电信", "300dx" },
			{ "300公用", "300gy" }, { "300成长", "300cz" }, { "300价值", "300jz" },
			{ "300R成长", "300rcz" }, { "300R价值", "300rjz" }, { "中证红利", "zzhl" },
			{ "公司债", "gsz" }, { "基本面50", "jbm50" }, { "中证央企", "zzyq" },
			{ "央企100", "yq100" }, { "中证能源", "zzny" }, { "中证材料", "zzcl" },
			{ "中证工业", "zzgy" }, { "中证可选", "zzkx" }, { "中证消费", "zzxf" },
			{ "中证医药", "zzyy" }, { "中证信息", "zzxx" }, { "中证电信", "zzdx" },
			{ "中证公用", "zzgy" }, { "中证民企", "zzmq" }, { "民企200", "mq200" },
			{ "内地地产", "nddc" }, { "内地农业", "ndny" }, { "300基建", "300jj" },
			{ "300银行", "300yh" }, { "300地产", "300dc" }, { "中证地企", "zzdq" },
			{ "中证国企", "zzgq" }, { "300运输", "300ys" }, { "创业成长", "cycz" },
			{ "银行99", "yh99" }, { "中证龙头", "zzlt" }, { "中证上游", "zzsy" },
			{ "中证中游", "zzzy" }, { "中证下游", "zzxy" }, { "基本200", "jb200" },
			{ "基本400", "jb400" }, { "基本600", "jb600" }, { "300周期", "300zq" },
			{ "300非周", "300fz" }, { "ESG 40", "esg40" }, { "等权90", "dq90" },
			{ "300沪市", "300hs" }, { "技术领先", "jslx" } };

	public static Activity lastActivity;

	public static int LAST_STOCK_GROUP_INFO_SCREEN_INDEX = 0;

	/** 程序用到的返回栈 */
	public static class GoBack {
		private static final String TAG = "GoBackStack";

		public static Stack<Bundle> goBackStack;

		public static void initialize() {
			if (goBackStack == null) {
				goBackStack = new Stack<Bundle>();
			} else {
				goBackStack.clear();
			}
		}

		public static Bundle pop() {
			if (goBackStack != null && !goBackStack.isEmpty()) {
				return goBackStack.pop();
			}
			return null;
		}

		public static void goBack(Activity ac) {
			goBack(ac, true);
		}

		/* 委托交易会用到此方法 */
		public static void goBack(Activity ac, boolean needResume) {
			final Bundle bundle = pop();
			boolean needClean = true;

			if (bundle != null) {
				Class<?> classType;
				String back2 = bundle.getString("back2");
				if (back2 != null) {
					try {
						classType = Class.forName(back2);
					} catch (ClassNotFoundException e) {
						classType = MainActivity.class;
					}
					MyApp.isFirstRun = false;
				} else {
					classType = MainActivity.class;
					MyApp.isFirstRun = true;
				}

				final int currentIndex = findActivity(ac.getClass().getName());
				destroyActivities(back2, currentIndex);

				if (needResume) {
					Intent intent = new Intent(ac, classType);
					intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);// 开启已在栈中的Activity
					ac.startActivity(intent);
				}

				needClean = bundle.getBoolean("needClean", true);
			} else {
				ac.finish();
			}
		}

		private static void destroyActivities(String back2, int fromIndex) {
			List<Activity> activityList = MyApp.activityList;
			final int length = activityList == null ? 0 : activityList.size();

			if (length < 1) {
				return;
			}

			final int toIndex = findActivity(back2);
			if (toIndex < 0) {
				return;
			}

			final int mainIndex = findActivity(MainActivity.class.getName());
			if (mainIndex < 0) {
				return;
			}

			// 委托交易向activtiyList下部添加，需分情况
			if (fromIndex > toIndex && toIndex >= mainIndex) {// 上部
				for (int i = fromIndex; i > toIndex; i--) {
					activityList.get(i).finish();
				}

				return;
			}

			if (fromIndex < toIndex && toIndex < mainIndex) {// 下部
				for (int i = toIndex - 1; i >= fromIndex; i--) {
					activityList.get(i).finish();
				}

				return;
			}

			if (fromIndex < mainIndex && toIndex >= mainIndex) {// 两端
				for (int i = activityList.size() - 1; i > toIndex; i--) {
					activityList.get(i).finish();
				}

				for (int i = mainIndex - 1; i >= fromIndex; i--) {
					activityList.get(i).finish();
				}

				return;
			}
		}

		/** 查找Activity，返回索引下标Index */
		private static int findActivity(String activityName) {
			List<Activity> activityList = MyApp.activityList;
			final int length = activityList == null ? 0 : activityList.size();
			if (length < 1) {
				return -1;
			}

			for (int i = length - 1; i >= 0; i--) {
				if (activityList.get(i).getClass().getName()
						.equals(activityName)) {
					return i;
				}
			}

			return -1;
		}

		/** len:从栈顶开始查找的长度 */
		private static int locate(String back2, int len) {
			if (goBackStack == null || goBackStack.isEmpty())
				return -1;

			int length = goBackStack.size();
			if (len > length)
				len = length;

			Bundle bundle;
			for (int i = length - 1; i >= length - len; i--) {
				bundle = goBackStack.elementAt(i);
				if (bundle.getString("back2").equals(back2))
					return i;
			}

			return -1;
		}

		private static int locate(String back2) {
			return locate(back2, goBackStack.size());
		}

		/** 以指定长度来收缩 */
		public static int shrink(String back2, int len) {
			int i = GoBack.locate(back2, len);
			if (i > 0)
				GoBack.goBackStack.setSize(i);

			return i;
		}

		/** 搜索栈中最近的一个相类似的bundle，收缩至其前一位置 */
		public static int shrink(String back2) {
			int i = GoBack.locate(back2);
			if (i >= 0)
				GoBack.goBackStack.setSize(i);

			return i;
		}

		/** 搜索栈中最近的一个相类似的bundle，收缩至其当前位置 */
		public static int shrinkAbove(String back2) {
			Logger.d("sss", back2);
			int i = GoBack.locate(back2);
			Logger.d("sss", "location:" + i);
			if (i >= 0)
				GoBack.goBackStack.setSize(i + 1);

			for (int j = 0; j < goBackStack.size(); j++) {
				Logger.d("sss", goBackStack.get(j).getString("back2"));
			}

			return i;
		}

		/* 是否在栈顶 */
		public static boolean isTop(String back2) {
			if (goBackStack != null && !goBackStack.isEmpty()) {
				return GoBack.goBackStack.peek().getString("back2")
						.equals(back2);
			}

			return false;
		}

		public static void clean() {
			if (goBackStack != null) {
				goBackStack.clear();
			}
		}
	}
}
